(function (angular) {
    var app = angular.module("coudanApp",["ngRoute"]);
    app.controller("filterCtrl",["$scope","$http","$location", function ($scope,$http,$location) {
        $http({
            method : "get",
            url : "http://139.199.192.48:9090/api/getgsshop",
        })
            .then(function (data) {
                $scope.shopsData = data.data.result;
                $scope.sname  = $scope.shopsData[0].shopName;
                $scope.sid  = $scope.shopsData[0].shopId;
            })
        $http({
            method : "get",
            url : "http://139.199.192.48:9090/api/getgsshoparea"
        })
            .then(function (data) {
                $scope.areaData = data.data.result;
                $scope.aname  = $scope.areaData[0].areaName.slice(0 ,2);
                $scope.aid = $scope.areaData[0].areaId;
            })
        $scope.shopChange = function (shop) {
            $scope.sname  = shop.shopName;
            $scope.sid = shop.shopId;
            $location.url("/"+$scope.sid+"/"+$scope.aid);
        }
        $scope.areaChange = function (area) {
            $scope.aname  = area.areaName.slice(0,2);
            $scope.aid = area.areaId;
            $location.url("/"+$scope.sid+"/"+$scope.aid);
        }
    }])
    app.config(["$routeProvider",function($routeProvider){
        $routeProvider
            .when("/:shopid?/:areaid?",{
                templateUrl : "../template/gsproductTpl.html",
                controller : "listCtrl"
            })
    }])
    app.controller("listCtrl",["$scope","$http","$routeParams", function ($scope,$http,$routParams) {
        $http({
            method : "get",
            url : "http://139.199.192.48:9090/api/getgsproduct",
            params : {
                shopid : $routParams.shopid||0,
                areaid : $routParams.areaid||0,
            }
        })
            .then(function (data) {
                $scope.list = data.data.result;
            })
    }])
})(angular)